<template>
	<view class="search-suggestions" v-if="visible && suggestions.length > 0">
		<view class="suggestions-list">
			<view class="suggestion-item" v-for="(item, index) in suggestions" :key="index"
				@click="handleSuggestionClick(item)">
				<view class="suggestion-icon">
					<text class="icon">🔍</text>
				</view>
				<view class="suggestion-content">
					<text class="suggestion-text">{{ item.text }}</text>
					<text class="suggestion-type">{{ item.type }}</text>
				</view>
				<view class="suggestion-arrow">
					<text class="arrow">↗</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		defineProps,
		defineEmits
	} from 'vue'

	const props = defineProps({
		visible: {
			type: Boolean,
			default: false
		},
		suggestions: {
			type: Array,
			default: () => []
		}
	})

	const emit = defineEmits(['suggestionClick'])

	const handleSuggestionClick = (suggestion) => {
		emit('suggestionClick', suggestion)
	}
</script>

<style lang="scss" scoped>
	.search-suggestions {
		position: absolute;
		top: 100%;
		left: 0;
		right: 0;
		background: white;
		border-radius: 0 0 24rpx 24rpx;
		box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.1);
		z-index: 1000;
		max-height: 600rpx;
		overflow-y: auto;

		.suggestions-list {
			.suggestion-item {
				display: flex;
				align-items: center;
				padding: 24rpx;
				border-bottom: 2rpx solid #f0f0f0;
				transition: background-color 0.2s ease;

				&:last-child {
					border-bottom: none;
				}

				&:active {
					background-color: #f8f9ff;
				}

				.suggestion-icon {
					margin-right: 24rpx;

					.icon {
						font-size: 32rpx;
						color: #999;
					}
				}

				.suggestion-content {
					flex: 1;

					.suggestion-text {
						display: block;
						font-size: 30rpx;
						color: #333;
						margin-bottom: 4rpx;
					}

					.suggestion-type {
						font-size: 24rpx;
						color: #999;
					}
				}

				.suggestion-arrow {
					.arrow {
						font-size: 28rpx;
						color: #ccc;
					}
				}
			}
		}
	}
</style>